package com.sgcc.sguap.bluefw.jit.resource;

import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.sgcc.sguap.bluefw.jit.domain.ProductLine;
import com.sgcc.sguap.bluefw.jit.repository.ProductLineDAO;

import io.dropwizard.hibernate.UnitOfWork;
import io.dropwizard.jersey.params.LongParam;

@Path("/productline")
@Produces(MediaType.APPLICATION_JSON)
public class ProductLineResource {
    private final ProductLineDAO productLineDAO;

    public ProductLineResource(ProductLineDAO productLineDAO) {
        this.productLineDAO = productLineDAO;
    }

    @POST    
    @UnitOfWork
    public ProductLine create(ProductLine productLine) {
        return productLineDAO.persist(productLine);
    }

    @PUT  
    @UnitOfWork
    public void update(ProductLine productLine) {
    	productLineDAO.persist(productLine);
    }
    
    @GET
    @Path("{id}")   
    @UnitOfWork
    public ProductLine find(@PathParam("id") LongParam id) {
        return productLineDAO.findById(id.get());
    }
    
    @GET
    @UnitOfWork
    public List<ProductLine> list() {
        return productLineDAO.findAll();
    }
    
    @DELETE
    @Path("{id}")   
    @UnitOfWork
    public void delete(@PathParam("id") LongParam id) {
        productLineDAO.delete(id.get());
    }
}
